from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text, ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.database import Base

class MCPService(Base):
    __tablename__ = "mcp_services"
    
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(100), nullable=False)
    description = Column(Text)
    service_type = Column(String(50), nullable=False)  # stdio, sse, streamable-http
    config = Column(Text, nullable=False)  # JSON格式存储服务配置
    knowledge_base_id = Column(Integer, ForeignKey("knowledge_bases.id"), nullable=False)
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())
    
    # 关系
    knowledge_base = relationship("KnowledgeBase", back_populates="mcp_services")
    
    def __repr__(self):
        return f"<MCPService(id={self.id}, name='{self.name}', type='{self.service_type}')>"